﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FirstFloor.Reversi.Messages
{
    /// <summary>
    /// Represents a location message.
    /// </summary>
    public abstract class LocationMessage
        : Message
    {
        private int x;
        private int y;

        /// <summary>
        /// Initializes a new instance of the <see cref="LocationMessage"/> class.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public LocationMessage(string name, int x, int y)
            : base(name)
        {
            this.x = x;
            this.y = y;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LocationMessage"/> class.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public LocationMessage(string name, string parameters)
            : base(name)
        {
            if (parameters == null) {
                throw new ArgumentNullException("parameters");
            }

            string[] parts = parameters.Split(',');

            this.x = int.Parse(parts[0]);
            this.y = int.Parse(parts[1]);
        }

        /// <summary>
        /// Gets the X.
        /// </summary>
        /// <value>The X.</value>
        public int X
        {
            get { return this.x; }
        }

        /// <summary>
        /// Gets the Y.
        /// </summary>
        /// <value>The Y.</value>
        public int Y
        {
            get { return this.y; }
        }

        /// <summary>
        /// Gets the string representation of the message parameters.
        /// </summary>
        /// <returns></returns>
        protected override string GetParameters()
        {
            return string.Format("{0},{1}", this.x, this.y);
        }
    }
}
